﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;

namespace webnew.BLL
{
    /// <summary>
    /// 业务逻辑类 Sys_Files
    /// </summary>
    public class Sys_Files
    {
        private readonly webnew.DAL.Sys_FilesHelper dal = new webnew.DAL.Sys_FilesHelper();
        public Sys_Files()
        { }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(List<webnew.Model.Sys_FilesInfo> lst)
        {
           return dal.Add(lst);
        }



        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string ID)
        {
            CheckConditionArgument(ID);
            dal.Del(ID);
        }

        /// <summary>
        /// 根据表名,表ID 获取文件列表数据
        /// </summary>
        /// <param name="tblName">表名</param>
        /// <param name="tblID">表ID</param>
        /// <returns></returns>
        public List<Model.Sys_FilesInfo> GetList(string tblName, string tblID)
        {
            return dal.GetList(tblName, tblID);
        }


        #region 验证参数的有效性，请在此加入更多业务逻辑的验证

        /// <summary>
        /// 验证实体的有效性
        /// </summary>
        private void CheckModel(webnew.Model.Sys_FilesInfo model)
        {
            if (model == null)
                throw new ArgumentNullException("参数不能为空。");

            if (!Regex.IsMatch(model.FileName, @"^[\s\w\u4e00-\u9fa5]{1,200}$"))
                throw new ArgumentException("FileName格式不正确。");

            if (!Regex.IsMatch(model.FileHref, @"^[\s\w\u4e00-\u9fa5]{1,1000}$"))
                throw new ArgumentException("FileHref格式不正确。");

            if (!Regex.IsMatch(model.TblName, @"^[\s\w\u4e00-\u9fa5]{1,100}$"))
                throw new ArgumentException("TblName格式不正确。");

            if (!Regex.IsMatch(model.TblID, @"^[\s\w\u4e00-\u9fa5]{1,20}$"))
                throw new ArgumentException("TblID格式不正确。");
        }

        /// <summary>
        /// 验证条件参数的有效性
        /// </summary>
        private void CheckConditionArgument(string ID)
        {
        }

        #endregion
    }
}
